package com.halloon.android.adapter;

import java.util.ArrayList;

import com.halloon.android.R;
import com.halloon.android.bean.UserBean;
import com.halloon.android.image.ImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LBSContactAdapter extends BaseAdapter{
	
	private Context context;
	private LayoutInflater layoutInflater;
	private ArrayList<UserBean> userBeans;
	
	public LBSContactAdapter(Context context, ArrayList<UserBean> userBeans){
		this.layoutInflater = LayoutInflater.from(context);
		this.context = context;
		this.userBeans = userBeans;
	}

	@Override
	public int getCount() {
		return userBeans.size();
	}

	@Override
	public UserBean getItem(int position) {
		return userBeans.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		UserHolder holder = null;
		
		UserBean userBean = getItem(position);
		if(userBean == null) return null;
		
		if(convertView == null){
			convertView = layoutInflater.inflate(R.layout.list_item_contact, null);
			
			holder = new UserHolder();
			holder.head = (ImageView) convertView.findViewById(R.id.picture);
			holder.nick = (TextView) convertView.findViewById(R.id.fullname);
			holder.sex = (ImageView) convertView.findViewById(R.id.sex);
			holder.tweet = (TextView) convertView.findViewById(R.id.headline);
			
			convertView.setTag(holder);
		}else{
			holder = (UserHolder) convertView.getTag();
		}
		
		ImageLoader.getInstance(context).displayImage(userBean.getHead()+"/50", holder.head, 4);
		holder.nick.setText(userBean.getNick());
		//holder.sex
		holder.tweet.setText(userBean.getTweetBean().getText());
		
		return convertView;
	}
	
	private static class UserHolder{
		ImageView head;
		ImageView sex;
		TextView nick;
		TextView tweet;
	}

}
